let app = getApp();
Page({
  data: {
    winHeight: 750,
    userInfo: [],
    pageNubmer: 1,
    allPageNubmer: 0,
  },
  onShow(){
    this.onLoad();
  },
  onLoad() {
    let that = this;
    wx.getStorage({
      key: 'openid',
      success(res) {
        that.setData({
          openid: res.data
        });
        that.loadOrderInfo();
      }
    });
  },
  loadOrderInfo() {
    wx.showLoading({
      title: '加载中...',
    })
    let that = this,
      pageNub = this.data.pageNubmer;
    app.get('DingDanDiZhi', {
      action: 'getDingDanByYeWuYuan',
      yema: that.data.pageNubmer,
      openid: that.data.openid
    }).then((res) => {
      wx.hideLoading();
      if (pageNub > 1) {
        that.setData({
          userInfo: that.data.userInfo.concat(res.data),
          allPageNubmer: Math.ceil((res.zongtiaoshu) / 10)
        })
      } else {
        that.setData({
          userInfo: res.data,
          allPageNubmer: Math.ceil((res.zongtiaoshu) / 10)
        });
      }
    });
  },
  itemPage(e) {
    wx.navigateTo({
      url: '/pages/clientOrderDetail/clientOrderDetail?orderId=' + e.currentTarget.id,
    });
  },
  onReachBottom() {    
    let pageNub = this.data.pageNubmer,
      allNumber = this.data.allPageNubmer,
      pageNubs = pageNub + 1;
    this.setData({
      pageNubmer: pageNubs
    });
    if ((this.data.pageNubmer > pageNub) && allNumber > 0) {
      return app.toast('没有更多数据');
    }
    this.loadOrderInfo();
  }
})